import { ECSSystem } from "../../../3rd/ECS/ECSSystem";
import { Vector3 } from "../../../Bridge/Vec";
import Util from "../../../Framework/Util/Util";
import { PositionComponent } from "../components/PositionComponent";
import { RenderNodeComponent } from "../components/RenderNodeComponent";

export class PositionSystem extends ECSSystem
{
    update()
    {

        // Util.Log("moveable hasComponent",movable);

        const positionComponents = this.ecs.components.all(PositionComponent);
        positionComponents.forEach(element => {
            if (Vector3.Distance(element.lastPos,element.pos) > 0.01 ) //数据有偏差猜进行下一步 
            {
                
                const entity = this.ecs.entities.get(element.entityId);
                if (entity.hasComponent(RenderNodeComponent))
                {
                    const render = entity.getComponent(RenderNodeComponent);
                    element.lastPos.Eval(element.pos);
                    render.node.SetPosition(element.pos);
                }
            }

        });
      

    }
}